package cn.xingyun.pickaxe_loli_new.mixin;

import cn.xingyun.pickaxe_loli_new.item.LolipickaxeItem;
import net.minecraft.world.level.entity.EntityAccess;
import net.minecraft.world.level.entity.LevelEntityGetter;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import net.minecraft.world.level.entity.TransientEntitySectionManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

public class PSEM_TSEM {
    @Mixin(PersistentEntitySectionManager.class)
    public static class PSEM_Mixin <T extends EntityAccess> {
        @Shadow public LevelEntityGetter entityGetter;

        @Inject(method = "addEntityWithoutEvent",at = @At("HEAD"),cancellable = true,remap = false)
        public void addEntityWE(T p_157539_, boolean p_157540_, CallbackInfoReturnable<Boolean> cir){
            if (LolipickaxeItem.DarkNameList.contains(p_157539_.getClass().getName())){
                cir.setReturnValue(false);
            }
            if(LolipickaxeItem.SentityGetter != null){
                entityGetter=LolipickaxeItem.SentityGetter;
            }
        }
    }
    @Mixin(TransientEntitySectionManager.class)
    public static class TESM_Mixin <T extends EntityAccess> {
        @Mutable
        @Shadow
        public LevelEntityGetter entityGetter;

        @Inject(method = "addEntity",at = @At("HEAD"),cancellable = true)
        public void addEntity(T p_157654_, CallbackInfo ci){
            if (LolipickaxeItem.DarkNameList.contains(p_157654_.getClass().getName())){
                ci.cancel();
            }
            if(LolipickaxeItem.CentityGetter != null){
                entityGetter=LolipickaxeItem.CentityGetter;
            }
        }
    }
}
